// components/PrivateRoute.js
import useAuth from './useAuth'; 
import PropTypes from 'prop-types';

const PrivateRoute = ({ children }) => {
    const { isAuthenticated, loading } = useAuth();

    if (loading) {
        return <div>Loading...</div>; 
    }

    if (!isAuthenticated) {
        // 如果未认证，则重定向到登录页面，并带上返回地址作为查询参数
        window.location.href = `http://localhost:5173`;
        return null;
    }

    return children;
};

PrivateRoute.propTypes = {
    children: PropTypes.node.isRequired,
};

export default PrivateRoute;